import { useState, useEffect } from 'react';

const useWindowResize = () => {
  const [height, setHeight] = useState(0);
  const [width, setWidth] = useState(0);

  const resizeUpdate = (e: any) => {
    const h = e.target.innerHeight;
    const w = e.target.innerWidth;
    setHeight(h);
    setWidth(w);
  };

  useEffect(() => {
    const h = window.innerHeight;
    const w = window.innerWidth;
    setHeight(h);
    setWidth(w);

    window.addEventListener('resize', resizeUpdate);

    return () => {
      window.removeEventListener('resize', resizeUpdate);
    }
  }, []);

  return { height, width };
};

export default useWindowResize;